Imports System.Text
Public Class frmGLRecurringPost
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents dgProduct As System.Windows.Forms.DataGrid
    Friend WithEvents dgProduct1 As System.Windows.Forms.DataGrid
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents tbRefer As System.Windows.Forms.TextBox
    Friend WithEvents tbDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmdPost As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.dgProduct = New System.Windows.Forms.DataGrid()
        Me.dgProduct1 = New System.Windows.Forms.DataGrid()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.tbRefer = New System.Windows.Forms.TextBox()
        Me.tbDate = New System.Windows.Forms.DateTimePicker()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdPost = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dgProduct1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'dgProduct
        '
        Me.dgProduct.BackColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgProduct.CaptionVisible = False
        Me.dgProduct.DataMember = ""
        Me.dgProduct.HeaderBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(128, Byte), Integer))
        Me.dgProduct.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgProduct.Location = New System.Drawing.Point(274, 45)
        Me.dgProduct.Name = "dgProduct"
        Me.dgProduct.Size = New System.Drawing.Size(321, 107)
        Me.dgProduct.TabIndex = 47
        '
        'dgProduct1
        '
        Me.dgProduct1.BackColor = System.Drawing.Color.AliceBlue
        Me.dgProduct1.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgProduct1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgProduct1.CaptionVisible = False
        Me.dgProduct1.DataMember = ""
        Me.dgProduct1.HeaderBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(128, Byte), Integer))
        Me.dgProduct1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgProduct1.Location = New System.Drawing.Point(9, 189)
        Me.dgProduct1.Name = "dgProduct1"
        Me.dgProduct1.ReadOnly = True
        Me.dgProduct1.Size = New System.Drawing.Size(586, 161)
        Me.dgProduct1.TabIndex = 50
        Me.dgProduct1.Visible = False
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(211, 168)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(194, 18)
        Me.Label2.TabIndex = 51
        Me.Label2.Text = "Details of selected transaction"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(330, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(169, 18)
        Me.Label3.TabIndex = 52
        Me.Label3.Text = "List of Transactions to Post"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'tbRefer
        '
        Me.tbRefer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbRefer.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbRefer.Location = New System.Drawing.Point(138, 45)
        Me.tbRefer.MaxLength = 10
        Me.tbRefer.Name = "tbRefer"
        Me.tbRefer.Size = New System.Drawing.Size(130, 26)
        Me.tbRefer.TabIndex = 185
        '
        'tbDate
        '
        Me.tbDate.CalendarTitleBackColor = System.Drawing.SystemColors.Desktop
        Me.tbDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.tbDate.Location = New System.Drawing.Point(9, 45)
        Me.tbDate.Name = "tbDate"
        Me.tbDate.Size = New System.Drawing.Size(99, 26)
        Me.tbDate.TabIndex = 187
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(135, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(52, 18)
        Me.Label1.TabIndex = 186
        Me.Label1.Text = "Refer #"
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label4.Location = New System.Drawing.Point(6, 25)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(38, 17)
        Me.Label4.TabIndex = 184
        Me.Label4.Text = "Date"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmdPost)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.dgProduct)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.tbRefer)
        Me.GroupPanel1.Controls.Add(Me.dgProduct1)
        Me.GroupPanel1.Controls.Add(Me.tbDate)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label4)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(622, 441)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 188
        Me.GroupPanel1.Text = "GL Recurring - Posting"
        '
        'cmdPost
        '
        Me.cmdPost.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPost.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPost.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPost.Location = New System.Drawing.Point(425, 368)
        Me.cmdPost.Name = "cmdPost"
        Me.cmdPost.Size = New System.Drawing.Size(82, 27)
        Me.cmdPost.TabIndex = 241
        Me.cmdPost.Text = "Post"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(513, 368)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 240
        Me.cmdExit.Text = "Exit"
        '
        'GLRecurringPost
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.Color.LightSteelBlue
        Me.ClientSize = New System.Drawing.Size(622, 441)
        Me.ControlBox = False
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(30, 70)
        Me.Name = "GLRecurringPost"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dgProduct1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub ICorderSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShowOrders()
    End Sub
    Private Sub ShowOrders()
        Dim GLdata As New GLdataLogic
        Dim ds As DataSet
        ds = GLdata.GetRecurTrxHeaderToPost(CompanyID)
        dgProduct.DataSource = ds.Tables(0)
        With dgProduct
            ' .BackgroundColor = GridBackgroundColor
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With

        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False
        dgformat(ds.Tables(0).Rows.Count)
        If ds.Tables(0).Rows.Count > 0 Then
            dgProduct.Select(dgProduct.CurrentRowIndex())
            ShowSubGrid()
        End If
        GLdata = Nothing
    End Sub
    Private Sub dgformat(ByVal RowCount As Integer)
        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .MappingName = "GJDATA"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With
        '
        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 200
        cs1.MappingName = "TRXNAME"
        cs1.HeaderText = "TRX.NAME"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        Dim cs2 As DataGridBoolColumn
        cs2 = New DataGridBoolColumn
        cs2.Width = 15
        cs2.MappingName = "POSTFLAG"
        cs2.ReadOnly = False
        cs2.FalseValue = 0
        cs2.TrueValue = 1
        cs2.AllowNull = False
        grdTableStyle.GridColumnStyles.Add(cs2)
        '
        dgProduct.TableStyles.Add(grdTableStyle)
    End Sub
    Private Sub dgformat2()
        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .MappingName = "GJRECURDATA"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With
        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 120
        cs1.MappingName = "ACNUM"
        cs1.HeaderText = "ACCOUNT"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 120
        cs1.MappingName = "ACCENT"
        cs1.HeaderText = "DPT"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)

        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 150
        cs1.MappingName = "ACDESC"
        cs1.HeaderText = "DESCRIPTION"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 95
        cs1.MappingName = "TRXAMTDR"
        cs1.HeaderText = "DEBIT"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 95
        cs1.MappingName = "TRXAMTCR"
        cs1.HeaderText = "CREDIT"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        dgProduct1.TableStyles.Add(grdTableStyle)
    End Sub
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub

    Private Sub dgProduct_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgProduct.MouseUp
        Try
            Dim pt As New Point(e.X, e.Y)
            Dim hti As DataGrid.HitTestInfo = dgProduct.HitTest(pt)
            If hti.Type = DataGrid.HitTestType.Cell Then
                dgProduct.CurrentCell = New DataGridCell(hti.Row, hti.Column)
                Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
                If dgProduct.Item(CurrentRow, 1) = True Then
                    dgProduct.Item(CurrentRow, 1) = False
                Else
                    dgProduct.Item(CurrentRow, 1) = True
                End If
                ShowSubGrid()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Private Sub ShowSubGrid()
        dgProduct1.Visible = True
        Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
        Dim sInvNo As String = dgProduct.Item(CurrentRow, 0)
        Dim GLdata As New GLdataLogic
        Dim ds As DataSet
        ds = GLdata.GetRecurTrx(CompanyID, sInvNo)
        dgProduct1.DataSource = ds.Tables(0)
        With dgProduct1
            ' .BackgroundColor = GridBackgroundColor
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With
        Dim cm As CurrencyManager = BindingContext(dgProduct1.DataSource, dgProduct1.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False
        dgformat2()
        GLdata = Nothing
    End Sub
    Private Sub dgProduct_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dgProduct.KeyPress
        ShowSubGrid()
    End Sub
    Private Sub cmdPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPost.Click
        If tbDate.Text = "" Or tbRefer.Text = "" Then
            MsgBox("Input required !", MsgBoxStyle.Critical, "Inventory Manager")
            tbRefer.Focus()
            Exit Sub
        End If
        Dim PostStatus As String
        PostStatus = PostJournalData()
        If PostStatus = "OK" Then
            MsgBox("Selected transactions posted !", MsgBoxStyle.Information, "Inventory Manager")
            ShowOrders()
        Else
            MsgBox("Unable to post the transactions." & vbLf & "Try Later", MsgBoxStyle.Critical, "Inventory Manager")
        End If
    End Sub
    Private Function PostJournalData() As String
        Dim InvXml As String
        Dim Response As String
        Dim GLdata As New GLdataLogic
        Dim sb As StringBuilder = New StringBuilder
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        Dim mrow, drow As Integer
        mrow = dv.Count
        Dim n As Integer
        sb.Append("<InvoiceDetails>")
        For n = 0 To mrow - 1
            If dgProduct.Item(n, 1) = 1 Or dgProduct.Item(n, 1).ToString.ToUpper = "TRUE" Then
                sb.Append("<InvoiceHead>")
                sb.Append("<TrxName>" + dgProduct.Item(n, 0) + "</TrxName>")
                sb.Append("<TrxDate>" + tbDate.Text + "</TrxDate>")
                sb.Append("<TrxRefer>" + tbRefer.Text + "</TrxRefer>")
                sb.Append("</InvoiceHead>")
            End If
        Next
        sb.Append("</InvoiceDetails>")
        '
        InvXml = sb.ToString()
        Response = GLdata.PostRecurData(CompanyID, "POST", InvXml)
        Return Response
    End Function
End Class
